package com.ysqcould.content.controller;

import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.message.domain.WxMessagePress;
import com.ysqcould.message.service.IWxMessagePressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 系统消息Controller
 * 
 * @author jcd
 * @date 2022-09-23
 */
@RestController
@RequestMapping("/content/sendMessage")
public class WxMessagePressController extends BaseController
{
    @Autowired
    private IWxMessagePressService wxMessagePressService;

    /**
     * 查询系统消息列表
     */
    @PreAuthorize("@ss.hasPermi('content:sendMessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxMessagePress wxMessagePress)
    {
        startPage();
        List<WxMessagePress> list = wxMessagePressService.selectWxMessagePressList(wxMessagePress);
        return getDataTable(list);
    }

    /**
     * 导出系统消息列表
     */
    @PreAuthorize("@ss.hasPermi('content:sendMessage:export')")
    @Log(title = "系统消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxMessagePress wxMessagePress)
    {
        List<WxMessagePress> list = wxMessagePressService.selectWxMessagePressList(wxMessagePress);
        ExcelUtil<WxMessagePress> util = new ExcelUtil<WxMessagePress>(WxMessagePress.class);
        util.exportExcel(response, list, "系统消息数据");
    }

    /**
     * 获取系统消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('content:sendMessage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxMessagePressService.selectWxMessagePressById(id));
    }

    /**
     * 新增系统消息
     */
    @PreAuthorize("@ss.hasPermi('content:sendMessage:add')")
    @Log(title = "系统消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxMessagePress wxMessagePress)
    {
        return toAjax(wxMessagePressService.insertWxMessagePress(wxMessagePress));
    }

    /**
     * 修改系统消息
     */
    @PreAuthorize("@ss.hasPermi('content:sendMessage:edit')")
    @Log(title = "系统消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxMessagePress wxMessagePress)
    {
        return toAjax(wxMessagePressService.updateWxMessagePress(wxMessagePress));
    }

    /**
     * 删除系统消息
     */
    @PreAuthorize("@ss.hasPermi('content:sendMessage:remove')")
    @Log(title = "系统消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxMessagePressService.deleteWxMessagePressByIds(ids));
    }
}
